package cn.bandeqing.dispatch.controller;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.dispatch.req.*;
import cn.bandeqing.dispatch.resp.DispatchWorkerTable;
import cn.bandeqing.dispatch.resp.HaveWorkerTable;
import cn.bandeqing.dispatch.resp.OrderDispatchTable;
import cn.bandeqing.dispatch.resp.WorkTimeTable;
import cn.bandeqing.dispatch.rpc.IDispatchRpc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/dispatch")
@RestController
@Tag(name = "调度")
public class DispatchController {

    @DubboReference
    private IDispatchRpc dispatchRpc;

    @Operation(summary = "forcePlan")
    @PostMapping("/forcePlan")
    public Resp<Void> forcePlan(@RequestBody @Valid DispatchForcePlanReq req) {
        return dispatchRpc.forcePlan(req);
    }

    @Operation(summary = "修改订单调度状态")
    @PostMapping("/modifyDispatchStatus")
    public Resp<Void> modifyDispatchStatus(@RequestBody @Valid MofifyDispatchStatusReq req) {
        return dispatchRpc.modifyDispatchStatus(req);
    }

    @Operation(summary = "modify")
    @PostMapping("/modify")
    public Resp<Void> modify(@RequestBody @Valid DispatchModifyReq req) {
        return dispatchRpc.modify(req);
    }

    @Operation(summary = "plan")
    @PostMapping("/plan")
    public Resp<Void> plan(@RequestBody @Valid DispatchPlanReq req) {
        return dispatchRpc.plan(req);
    }

    @Operation(summary = "dispatchWorkertable")
    @PostMapping("/dispatchWorkertable")
    public Resp<Table<DispatchWorkerTable>> dispatchWorkertable(@RequestBody @Valid DispatchWorkerTableReq req) {
        return dispatchRpc.dispatchWorkertable(req);
    }

    @Operation(summary = "haveWorkertable")
    @PostMapping("/haveWorkertable")
    public Resp<Table<HaveWorkerTable>> haveWorkertable(@RequestBody @Valid HaveWorkerTableReq req) {
        return dispatchRpc.haveWorkertable(req);
    }

    @Operation(summary = "表格")
    @PostMapping("/table")
    public Resp<Table<OrderDispatchTable>> table(@RequestBody @Valid OrderDispatchTableReq req) {
        return dispatchRpc.table(req);
    }

    @Operation(summary = "modifySwitch")
    @PostMapping("/workTime/modifySwitch")
    public Resp<Void> modifyWorkTimeSwitch(@RequestBody @Valid ModifyWorkTimeSwitchReq req) {
        return dispatchRpc.modifyWorkTimeSwitch(req);
    }

    @Operation(summary = "表格")
    @PostMapping("/workTime/table")
    public Resp<Table<WorkTimeTable>> workTimeTable(@RequestBody @Valid WorkTimeTableReq req) {
        return dispatchRpc.workTimeTable(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/workTime/saveOrUpdate")
    public Resp<Void> saveOrUpdate(@RequestBody @Valid WorkTimeSaveOrUpdateReq req) {
        dispatchRpc.saveOrUpdate(req);
        return Resp.success();
    }

}
